<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>commands &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../index.html" />
    <link rel="next" title="config" href="config.html" />
    <link rel="prev" title="channelbase" href="channelbase.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="config.html" title="config"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="channelbase.html" title="channelbase"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="commands">
<h1>commands<a class="headerlink" href="#commands" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-gozerlib.commands">
<h2>description<a class="headerlink" href="#module-gozerlib.commands" title="Permalink to this headline">¶</a></h2>
<p>gozerwave commands.</p>
<dl class="class">
<dt id="gozerlib.commands.Command">
<em class="property">class </em><tt class="descclassname">gozerlib.commands.</tt><tt class="descname">Command</tt><big>(</big><em>modname</em>, <em>cmnd</em>, <em>func</em>, <em>perms=</em><span class="optional">[</span><span class="optional">]</span>, <em>options={}</em>, <em>allowqueue=True</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Command" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="(in Python v2.7)" class="reference external" href="http://docs.python.org/dev/library/functions.html#object"><tt class="xref docutils literal"><span class="pre">object</span></tt></a></p>
<p>a gozerwave command object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><em>modname</em> (string) &#8211; the module name in which this command is registered</li>
<li><em>cmnd</em> (string) &#8211; the command</li>
<li><em>func</em> (function or method) &#8211; function handling the command</li>
<li><em>perms</em> (list of strings) &#8211; permission needed to be allowed to do this command</li>
<li><em>options</em> (dict) &#8211; options used in this command</li>
<li><em>allowqueue</em> (boolean) &#8211; whether this command can have queues attached</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="class">
<dt id="gozerlib.commands.Commands">
<em class="property">class </em><tt class="descclassname">gozerlib.commands.</tt><tt class="descname">Commands</tt><a class="headerlink" href="#gozerlib.commands.Commands" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="(in Python v2.7)" class="reference external" href="http://docs.python.org/dev/library/functions.html#object"><tt class="xref docutils literal"><span class="pre">object</span></tt></a></p>
<p>the commands object holds all commands of the bot.</p>
<dl class="method">
<dt id="gozerlib.commands.Commands.add">
<tt class="descname">add</tt><big>(</big><em>cmnd</em>, <em>func</em>, <em>perms=</em><span class="optional">[</span><span class="optional">]</span>, <em>threaded=False</em>, <em>options={}</em>, <em>allowqueue=False</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.add" title="Permalink to this definition">¶</a></dt>
<dd><p>add a command.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>cmnd</em> (string) &#8211; the command</li>
<li><em>func</em> (function or method) &#8211; function handling the command</li>
<li><em>perms</em> (list of strings) &#8211; permission needed to be allowed to do this command</li>
<li><em>threaded</em> &#8211; whether this command need to be executed in its own thread</li>
<li><em>options</em> (dict) &#8211; options used in this command</li>
<li><em>allowqueue</em> (boolean) &#8211; whether this command can have queues attached</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">self</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.commands.Commands.apropos">
<tt class="descname">apropos</tt><big>(</big><em>search</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.apropos" title="Permalink to this definition">¶</a></dt>
<dd><p>search existing commands for search term.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>search</em> (string) &#8211; text to search for</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">list of plugin names</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.commands.Commands.dispatch">
<tt class="descname">dispatch</tt><big>(</big><em>bot</em>, <em>event</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.dispatch" title="Permalink to this definition">¶</a></dt>
<dd><p>dispatch an event if cmnd exists and user is allowed to exec this command.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>bot</em> (gozerlib.botbase.BotBase) &#8211; the bot on which event originated</li>
<li><em>event</em> (gozerlib.eventbase.EventBase) &#8211; event to dispatch</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">None</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.commands.Commands.exists">
<tt class="descname">exists</tt><big>(</big><em>cmnd</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.exists" title="Permalink to this definition">¶</a></dt>
<dd><p>see if a command exists.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>cmnd</em> (string) &#8211; the command to test if it exists</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">boolean</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.commands.Commands.gethelp">
<tt class="descname">gethelp</tt><big>(</big><em>cmnd</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.gethelp" title="Permalink to this definition">¶</a></dt>
<dd><p>get the docstring of a command. used for help.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>cmnd</em> (string) &#8211; command to get docstring of</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">string</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.commands.Commands.list">
<tt class="descname">list</tt><big>(</big><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.list" title="Permalink to this definition">¶</a></dt>
<dd><p>return list of all plugins.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">list of plugins (strings)</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.commands.Commands.perms">
<tt class="descname">perms</tt><big>(</big><em>cmnd</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.perms" title="Permalink to this definition">¶</a></dt>
<dd><p>show what permissions are needed to execute cmnd</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>cmnd</em> (string) &#8211; command to get parameters for</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">list of permissions (strings) or None</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.commands.Commands.unload">
<tt class="descname">unload</tt><big>(</big><em>modname</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.unload" title="Permalink to this definition">¶</a></dt>
<dd><p>remove modname registered commands from store.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>modname</em> (string) &#8211; name of the module to unload</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">self</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.commands.Commands.whereis">
<tt class="descname">whereis</tt><big>(</big><em>cmnd</em><big>)</big><a class="headerlink" href="#gozerlib.commands.Commands.whereis" title="Permalink to this definition">¶</a></dt>
<dd><p>return plugin name in which command is implemented.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>cmnd</em> (string) &#8211; command to get plugin for</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">string (plugin name)</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/commands.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; gozerwave commands. &quot;&quot;&quot;</span>

<span class="c">## gozerlib imports</span>

<span class="kn">from</span> <span class="nn">gozerlib.utils.xmpp</span> <span class="kn">import</span> <span class="n">stripped</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.trace</span> <span class="kn">import</span> <span class="n">calledfrom</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.exception</span> <span class="kn">import</span> <span class="n">handle_exception</span>
<span class="kn">from</span> <span class="nn">gozerlib.users</span> <span class="kn">import</span> <span class="n">GozerUsers</span>

<span class="c">## basic imports</span>

<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">sys</span>

<span class="k">class</span> <span class="nc">Command</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">        a gozerwave command object. </span>

<span class="sd">        :param modname: the module name in which this command is registered</span>
<span class="sd">        :type modname: string</span>
<span class="sd">        :param cmnd: the command</span>
<span class="sd">        :type cmnd: string</span>
<span class="sd">        :param func: function handling the command</span>
<span class="sd">        :type func: function or method</span>
<span class="sd">        :param perms: permission needed to be allowed to do this command</span>
<span class="sd">        :type perms: list of strings</span>
<span class="sd">        :param options: options used in this command</span>
<span class="sd">        :type options: dict</span>
<span class="sd">        :param allowqueue: whether this command can have queues attached</span>
<span class="sd">        :type allowqueue: boolean</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modname</span><span class="p">,</span> <span class="n">cmnd</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">perms</span><span class="o">=</span><span class="p">[],</span> <span class="n">options</span><span class="o">=</span><span class="p">{},</span> <span class="n">allowqueue</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">modname</span> <span class="o">=</span> <span class="n">modname</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plugname</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">modname</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mf">1</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cmnd</span> <span class="o">=</span> <span class="n">cmnd</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">func</span> <span class="o">=</span> <span class="n">func</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">perms</span> <span class="o">=</span> <span class="n">perms</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plugin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">plugname</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="n">options</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">allowqueue</span> <span class="o">=</span> <span class="n">allowqueue</span>

<span class="k">class</span> <span class="nc">Commands</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; the commands object holds all commands of the bot. &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">store</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmnd</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">perms</span><span class="o">=</span><span class="p">[],</span> <span class="n">threaded</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="p">{},</span> <span class="n">allowqueue</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            add a command. </span>

<span class="sd">            :param cmnd: the command</span>
<span class="sd">            :type cmnd: string</span>
<span class="sd">            :param func: function handling the command</span>
<span class="sd">            :type func: function or method</span>
<span class="sd">            :param perms: permission needed to be allowed to do this command</span>
<span class="sd">            :type perms: list of strings</span>
<span class="sd">            :param threaded: whether this command need to be executed in its own thread</span>
<span class="sd">            :type plugin: boolean</span>
<span class="sd">            :param options: options used in this command</span>
<span class="sd">            :type options: dict</span>
<span class="sd">            :param allowqueue: whether this command can have queues attached</span>
<span class="sd">            :type allowqueue: boolean</span>
<span class="sd">            :rtype: self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">modname</span> <span class="o">=</span> <span class="n">calledfrom</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">_getframe</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">cmnd</span><span class="p">]</span> <span class="o">=</span> <span class="n">Command</span><span class="p">(</span><span class="n">modname</span><span class="p">,</span> <span class="n">cmnd</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">perms</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">allowqueue</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">def</span> <span class="nf">dispatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            dispatch an event if cmnd exists and user is allowed to exec this command.</span>

<span class="sd">            :param bot: the bot on which event originated</span>
<span class="sd">            :type bot: gozerlib.botbase.BotBase</span>
<span class="sd">            :param event: event to dispatch</span>
<span class="sd">            :type event: gozerlib.eventbase.EventBase</span>
<span class="sd">            :rtype: None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="kn">from</span> <span class="nn">gozerlib.aliases</span> <span class="kn">import</span> <span class="n">aliascheck</span>
        <span class="n">aliascheck</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
        <span class="n">cmnd</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">txt</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mf">0</span><span class="p">]</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">cmnd</span><span class="p">):</span>

            <span class="c">## core business</span>

            <span class="k">try</span><span class="p">:</span>
                <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">cmnd</span><span class="p">]</span>
                <span class="nb">id</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">auth</span> <span class="ow">or</span> <span class="n">stripped</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>
                <span class="n">users</span> <span class="o">=</span> <span class="n">GozerUsers</span><span class="p">()</span>

                <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">allowed</span><span class="p">(</span><span class="nb">id</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">perms</span><span class="p">):</span>
                    <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;dispatching </span><span class="si">%s</span><span class="s"> for </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cmnd</span><span class="p">,</span> <span class="nb">id</span><span class="p">))</span>
                    <span class="n">c</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">)</span>

                <span class="k">else</span><span class="p">:</span>

                    <span class="k">if</span> <span class="ow">not</span> <span class="s">&#39;OPER&#39;</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">perms</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">users</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="nb">id</span><span class="p">):</span>

                        <span class="k">if</span> <span class="n">users</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="nb">id</span><span class="p">,</span> <span class="p">[</span><span class="nb">id</span><span class="p">,</span> <span class="p">],</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="p">]):</span>

                            <span class="k">if</span> <span class="s">&#39;USER&#39;</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">perms</span><span class="p">:</span>
                                <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;dispatching </span><span class="si">%s</span><span class="s"> for </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cmnd</span><span class="p">,</span> <span class="nb">id</span><span class="p">))</span>
                                <span class="n">c</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">event</span><span class="p">)</span>

                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> is not allowed to do </span><span class="si">%s</span><span class="s"> command&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">id</span><span class="p">,</span> <span class="n">cmnd</span><span class="p">))</span>

            <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
                <span class="n">handle_exception</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">queues</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">queue</span> <span class="ow">in</span> <span class="n">event</span><span class="o">.</span><span class="n">queues</span><span class="p">:</span>
                    <span class="n">queue</span><span class="o">.</span><span class="n">put_nowait</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">event</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;no such command: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">cmnd</span><span class="p">)</span>


    <span class="k">def</span> <span class="nf">unload</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">modname</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            remove modname registered commands from store.</span>

<span class="sd">            :param modname: name of the module to unload</span>
<span class="sd">            :type modname: string</span>
<span class="sd">            :rtype: self</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">delete</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">cmnd</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">cmnd</span><span class="o">.</span><span class="n">modname</span> <span class="o">==</span> <span class="n">modname</span><span class="p">:</span>
                <span class="n">delete</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cmnd</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">cmnd</span> <span class="ow">in</span> <span class="n">delete</span><span class="p">:</span>
            <span class="k">del</span> <span class="n">cmnd</span>

        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">def</span> <span class="nf">exists</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmnd</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            see if a command exists.</span>

<span class="sd">            :param cmnd: the command to test if it exists</span>
<span class="sd">            :type cmnd: string</span>
<span class="sd">            :rtype: boolean</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">cmnd</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">True</span>

        <span class="k">return</span> <span class="bp">False</span>

    <span class="k">def</span> <span class="nf">apropos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">search</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            search existing commands for search term. </span>

<span class="sd">            :param search: text to search for</span>
<span class="sd">            :type search: string</span>
<span class="sd">            :rtype: list of plugin names</span>
<span class="sd"> </span>
<span class="sd">        &quot;&quot;&quot;</span>
 
        <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">cmnd</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>

            <span class="k">if</span> <span class="n">search</span> <span class="ow">in</span> <span class="n">name</span><span class="p">:</span>
                <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">result</span>

    <span class="k">def</span> <span class="nf">perms</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmnd</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            show what permissions are needed to execute cmnd</span>

<span class="sd">            :param cmnd: command to get parameters for</span>
<span class="sd">            :type cmnd: string</span>
<span class="sd">            :rtype: list of permissions (strings) or None</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">cmnd</span><span class="p">]</span><span class="o">.</span><span class="n">perms</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">):</span>
            <span class="k">return</span>

    <span class="k">def</span> <span class="nf">list</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            return list of all plugins. </span>

<span class="sd">            :rtype: list of plugins (strings)</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">whereis</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmnd</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot; </span>
<span class="sd">            return plugin name in which command is implemented. </span>

<span class="sd">            :param cmnd: command to get plugin for</span>
<span class="sd">            :type cmnd: string</span>
<span class="sd">            :rtype: string (plugin name)</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">cmnd</span><span class="p">]</span><span class="o">.</span><span class="n">plugname</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">return</span>

    <span class="k">def</span> <span class="nf">gethelp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmnd</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            get the docstring of a command. used for help.</span>

<span class="sd">            :param cmnd: command to get docstring of</span>
<span class="sd">            :type cmnd: string</span>
<span class="sd">            :rtype: string</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">cmnd</span><span class="p">]</span><span class="o">.</span><span class="n">func</span><span class="o">.</span><span class="n">__doc__</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">AttributeError</span><span class="p">):</span>
            <span class="k">return</span>

<span class="c"># the command object</span>
<span class="n">cmnds</span> <span class="o">=</span> <span class="n">Commands</span><span class="p">()</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">commands</a><ul>
<li><a class="reference external" href="#module-gozerlib.commands">description</a></li>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="channelbase.html"
                                  title="previous chapter">channelbase</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="config.html"
                                  title="next chapter">config</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/gozerlib/commands.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="config.html" title="config"
             >next</a> |</li>
        <li class="right" >
          <a href="channelbase.html" title="channelbase"
             >previous</a> |</li>
        <li><a href="../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>